#!/bin/bash -e

function info() {
    echo Usage: `basename $0` 'bam'
    exit 1
}

while getopts ":p:f:c:" opt; do
    case  $opt  in
        p) out_prefix=$OPTARG;;
        f) suffix=$OPTARG;;
        c) cov_min=$OPTARG;;
        *) info;;
    esac
done
shift $(($OPTIND - 1))

if [ $# -lt 1 ]; then info; fi

. $var

umi_group.sh -p$out_prefix $1
cut -f1,6,8,9 $out_prefix.group.tsv > $out_prefix.group.txt
tes_filter_umi.py -c${cov_min:=2} $out_prefix.group.bam $out_prefix.group.txt $out_prefix.umi_filter.bam

bam_sort_index.sh -p$out_prefix.umi_filter $out_prefix.umi_filter.bam

umi.sh -p$out_prefix $out_prefix.umi_filter.sort.bam

. $cmd_done
